package com.lsh.oms.core.service.query;

import com.alibaba.fastjson.JSONObject;
import com.lsh.oms.core.enums.*;

/**
 * Project Name: lsh-oms
 * Created by peter on 2020-01-16.
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
public class ConfigBuilder {

    public static JSONObject getConfig(InterfaceEnum interfaceEnum) {

        JSONObject config = new JSONObject();

        Integer index = interfaceEnum.getTmsConfig().getIndex();

        if (index == 2) {

            return getConfigShipping();
        }

        if (index == 3) {

            return getConfigReceipt();
        }

        if (index == 4) {

            return getConfigReturn();
        }

        return config;
    }

    public static JSONObject getConfigShipping() {

        JSONObject config = new JSONObject();

        JSONObject orderStatusJson = new JSONObject(true);
        for (ShippingStatus orderStatus : ShippingStatus.values()) {
            orderStatusJson.put(String.valueOf(orderStatus.getIndex()), orderStatus.getName());
        }

        JSONObject orderTypeJson = new JSONObject(true);
        for (MisOrderType orderType : MisOrderType.values()) {
            orderTypeJson.put(String.valueOf(orderType.getCode()), orderType.getName());
        }

        JSONObject delayTypeJson = new JSONObject(true);
        for (DelayType delayType : DelayType.values()) {
            delayTypeJson.put(String.valueOf(delayType.getIndex()), delayType.getDesc());
        }

        config.put("order_status", orderStatusJson);
        config.put("order_type", orderTypeJson);
        config.put("delay_type", delayTypeJson);

        return config;
    }


    public static JSONObject getConfigReceipt() {

        JSONObject config = new JSONObject();

        JSONObject orderStatusJson = new JSONObject(true);
        for (SignStatus orderStatus : SignStatus.values()) {
            orderStatusJson.put(String.valueOf(orderStatus.getIndex()), orderStatus.getName());
        }

        JSONObject payTypeJson = new JSONObject(true);
        for (PayChannel payChannel : PayChannel.values()) {
            payTypeJson.put(String.valueOf(payChannel.getIndex()), payChannel.getName());
        }

        JSONObject orderTypeJson = new JSONObject(true);
        for (MisOrderType orderType : MisOrderType.values()) {
            orderTypeJson.put(String.valueOf(orderType.getCode()), orderType.getName());
        }

        JSONObject payStatusJson = new JSONObject(true);
        for (PayStatus payStatus : PayStatus.values()) {
            payStatusJson.put(String.valueOf(payStatus.getValue()), payStatus.getDesc());
        }


        JSONObject statusMemoJson = new JSONObject(true);
        for (StatusMemo payStatus : StatusMemo.values()) {
            statusMemoJson.put(String.valueOf(payStatus.getCode()), payStatus.getName());
        }

        config.put("order_status", orderStatusJson);
        config.put("pay_type", payTypeJson);
        config.put("order_type", orderTypeJson);
        config.put("pay_status", payStatusJson);
        config.put("status_memo", statusMemoJson);


        return config;
    }

    public static JSONObject getConfigReturn() {

        JSONObject config = new JSONObject();

        JSONObject orderStatusJson = new JSONObject(true);
        for (ReturnStatus orderStatus : ReturnStatus.values()) {
            orderStatusJson.put(String.valueOf(orderStatus.getIndex()), orderStatus.getName());
        }

        JSONObject orderTypeJson = new JSONObject(true);
        for (MisOrderType orderType : MisOrderType.values()) {
            orderTypeJson.put(String.valueOf(orderType.getCode()), orderType.getName());
        }

        JSONObject returnTypeJson = new JSONObject(true);
        for (ReturnType orderType : ReturnType.values()) {
            returnTypeJson.put(String.valueOf(orderType.getIndex()), orderType.getName());
        }

        JSONObject returnOrderTypeJson = new JSONObject(true);
        for (ReturnOrderType orderType : ReturnOrderType.values()) {
            returnOrderTypeJson.put(String.valueOf(orderType.getIndex()), orderType.getName());
        }

        config.put("order_status", orderStatusJson);
        config.put("return_type", returnTypeJson);
        config.put("order_type", orderTypeJson);
        config.put("return_order_type", returnOrderTypeJson);

        return config;
    }


}
